package com.flowabledemo.controller;

import com.dto.RequestDto;
import com.dto.ResponseDto;
import com.flowabledemo.dto.TestUserDto;
import com.flowabledemo.service.TestUserService;
import com.flowabledemo.vo.TestUserVo;
import com.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :zhoushunquan
 * @description: 用户模板 controller
 * @create date: 2022-02-17 16:47:32
 */


@RestController
@RequestMapping(value = "testUser")
@Api(value = "TestUsercontroller", tags = {"用户模板 信息接口"})
public class TestUserController {

    @Autowired
    TestUserService testUserService;

    @ApiOperation(value = "添加用户模板信息", httpMethod = "POST")
    @PostMapping(value = "add")
    public ResponseDto<Integer> add(@RequestBody @Validated(TestUserDto.Add.class) RequestDto<TestUserDto> requestDto) {
        return testUserService.add(requestDto.getData()) > 0 ?
                ResponseUtil.success() : ResponseUtil.fail();
    }

    @ApiOperation(value = "修改用户模板信息", httpMethod = "POST")
    @PostMapping(value = "update")
    public ResponseDto<Integer> update(@RequestBody @Validated(TestUserDto.Update.class) RequestDto<TestUserDto> requestDto) {
        return testUserService.update(requestDto.getData()) > 0 ?
                ResponseUtil.success() : ResponseUtil.fail();
    }

    @ApiOperation(value = "删除用户模板信息", httpMethod = "POST")
    @PostMapping(value = "del")
    public ResponseDto<Integer> del(@RequestBody @Validated(TestUserDto.Delete.class) RequestDto<TestUserDto> requestDto) {
        return testUserService.delete(requestDto.getData().getId()) > 0 ?
                ResponseUtil.success() : ResponseUtil.fail();
    }

    @ApiOperation(value = "查询用户模板信息详情", httpMethod = "POST")
    @RequestMapping(value = "get", method = RequestMethod.POST)
    public ResponseDto<TestUserVo> get(@RequestBody RequestDto<TestUserDto> requestDto) {
        return ResponseUtil.success(testUserService.get(requestDto.getData().getId()));
    }

    @ApiOperation(value = "查询用户模板信息列表", httpMethod = "POST")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public ResponseDto<List<TestUserVo>> findList(@RequestBody RequestDto<TestUserDto> requestDto) {
        return ResponseUtil.successList(testUserService.findList(requestDto.getData()));
    }

    @ApiOperation(value = "查询用户模板分页列表信息", httpMethod = "POST")
    @RequestMapping(value = "pagelist", method = RequestMethod.POST)
    public ResponseDto findPageList(@RequestBody RequestDto<TestUserDto> requestDto) {
        return null;
    }
}